//
//  GlobalDefine.h
//  EnglishWeekly
//
//  Created by admin on 15/3/24.
//  Copyright (c) 2015年 iflytek. All rights reserved.
//

#ifndef EnglishWeekly_GlobalDefine_h
#define EnglishWeekly_GlobalDefine_h


#pragma mark - Path相关

#define PATH_OF_APP_HOME    NSHomeDirectory()
#define PATH_OF_TEMP        NSTemporaryDirectory()
#define PATH_OF_DOCUMENT    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]
#define PATH_OF_CACHE       NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0]


#pragma mark - UIConstants provides contants variables for UI control.

///屏幕宽度
#define SCREEN_WIDTH    ([UIScreen mainScreen].bounds.size.width)
///屏幕高度
#define SCREEN_HEIGHT   ([UIScreen mainScreen].bounds.size.height)
///高保真显示宽度转到对应手机上的宽度 WIDTH为标注宽度
#define REAL_VIEW_WIDTH (WIDTH) WIDTH / 375.0 * SCREEN_WIDTH
///高保真显示宽度转到对应手机上的宽度 HEIGHT为标注高度
#define REAL_VIEW_HEIGHT (HEIGHT) HEIGHT / 667.0 * SCREEN_HEIGHT
///高保真显示size转到对应手机上的size WIDTH为标注宽度 HEIGHT为标注高度
#define REAL_VIEW_SIZE(WIDTH,HEIGHT)      CGSizeMake(WIDTH / 375.0 * SCREEN_WIDTH, HEIGHT / 667.0 * SCREEN_HEIGHT)

#define UI_NAVIGATION_BAR_HEIGHT    44
#define UI_TAB_BAR_HEIGHT           49
#define UI_STATUS_BAR_HEIGHT        (iPhoneX ? 44 : 20)
#define SafeAreaBottomHeight        (iPhoneX ? 34 : 0)
#define UI_SCREEN_WIDTH             ([[UIScreen mainScreen] bounds].size.width)
#define UI_SCREEN_HEIGHT            ([[UIScreen mainScreen] bounds].size.height)

#define UI_LABEL_LENGTH             200
#define UI_LABEL_HEIGHT             15
#define UI_LABEL_FONT_SIZE          12
#define UI_LABEL_FONT               [UIFont systemFontOfSize:UI_LABEL_FONT_SIZE]


#pragma mark - System Versioning Preprocessor Macros

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

//当前语言
#define CURRENTLANGUAGE           ([[NSLocale preferredLanguages] objectAtIndex:0])


//打破循环引用
#define WS(weakSelf) __weak __typeof(&*self)weakSelf = self;
//空字符串
#define EMPTY_STRING        @""
//NSUserDefaults
#define USER_DEFAULT    [NSUserDefaults standardUserDefaults]
//iOSApp版本号
#define iOSAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

#define KeyWindow       [UIApplication sharedApplication].keyWindow


#define FontSize(fontSize)      [UIFont systemFontOfSize:fontSize]
#define BoldFontSize(fontSize)  [UIFont boldSystemFontOfSize:fontSize]

#define IOS_VERSION_7_OR_ABOVE (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)? (YES):(NO))
#define ABOVE_IOS_VERSION_8 (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)? (YES):(NO))
#define ABOVE_IOS_VERSION_11 (([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0)? (YES):(NO))
#define kNavigateBarHeight ( IOS_VERSION_7_OR_ABOVE ? 64.0 : 44.0 )
#define kStatusBarHeight 20

#define kTabbarHeight 49

#pragma mark - 相关设备判断

#define IOS_SCREEN_SIZE_IS_4INCH (([[UIScreen mainScreen] bounds].size.height == 568)? (YES):(NO))
#define IOS_SCREEN_SIZE_IS_3_5INCH (([[UIScreen mainScreen] bounds].size.height == 480)? (YES):(NO))
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define IS_SCREEN_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_SCREEN_4_0 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_SCREEN_4_7 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_SCREEN_5_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone6plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)

#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

#pragma mark - 颜色相关

#define RGBA(r,g,b,a)   [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b)      RGBA(r,g,b,1.0f)
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define UIColorFromRGBA(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]

#define UIIMAGE(name)   [UIImage imageNamed:name]

#define DefaultColor    UIColorFromRGB(0xFF606A)
#define DefaultBackgroundColor UIColorFromRGB(0xF2F2F2)

#define ButtonHighlightedColor    UIColorFromRGB(0xE44D58)


#endif
